using Microsoft.AspNetCore.Mvc;
using MyMvcApp.Models;
using System.Text;

namespace MyMvcApp.Controllers
{
    public class PracticeController : Controller
    {
        // 方法一：渲染简单数据
        public IActionResult RenderSimpleData()
        {
            string message = "你好";
            return Content(message);
        }

        // 方法二：渲染复杂数据
        public IActionResult RenderComplexData()
        {
            var blog = new BlogCreateDto
            {
                Title = "测试标题",
                Author = "张三",
                Content = "你好好好好"
            };

            return Content($"标题: {blog.Title}, 作者: {blog.Author}, 内容: {blog.Content}");
        }

        // 方法三：渲染集合数据
        public IActionResult RenderCollectionData()
        {
            var blogs = new List<BlogCreateDto>{
                new BlogCreateDto { Title = "标题1", Author = "作者1", Content = "你好好好好" },
                new BlogCreateDto { Title = "标题2", Author = "作者2", Content = "你好好好好你好好好好" },
                new BlogCreateDto { Title = "标题3", Author = "作者3", Content = "你好好好好你好好好好你好好好好" }
            };

            string result = "";

            foreach (var blog in blogs)
            {
                result += $"标题: {blog.Title}, 作者: {blog.Author}, 内容: {blog.Content} <br/>";
            }

            return Content(result, "text/html; charset=utf-8");
        }
    }
}